﻿using System;
using System.Linq;
using System.IO;
using System.IO.IsolatedStorage;
using System.Collections.Generic;
using Microsoft.LightSwitch;
using Microsoft.LightSwitch.Framework.Client;
using Microsoft.LightSwitch.Presentation;
using Microsoft.LightSwitch.Presentation.Extensions;
using System.Windows.Controls;

namespace LightSwitchApplication {
    public partial class Home {

        partial void ManagementCustomer_Execute() {
            if (this.Application.CurrentUser.Name == "Supervisor")	{
                Application.ShowSupervisorCustomers();
	        }
            else { ShowWarning();}
        }

        partial void ManagementTool_Execute() {
            if (this.Application.CurrentUser.Name == "Supervisor") {
                Application.ShowSupervisorTools(null);
            }
            else { ShowWarning(); }
        }

        partial void ManageUser_Execute() {
            if (this.Application.CurrentUser.Name == "Supervisor") {
                Application.ShowSupervisorUsers();
            }
            else { ShowWarning(); }
        } 

        partial void Microsection_Execute() {
            if (this.Application.CurrentUser.Auth) {
                Application.ShowOperatorMicrosection();    
            }
            else { ShowWarning(); }
        }

        partial void SearchBox_Execute() {
            if (this.Application.CurrentUser.Auth) {
                Application.ShowOperatorSearchBox();
            }
            else { ShowWarning(); }
        }

        partial void SearchBag_Execute() {
            Application.ShowVisitorSearchBag();
        }
        partial void SearchTool_Execute() {
            Application.ShowVisitorSearchTool(null);

        }

        void ShowWarning() {
            string Message = "You are not authorized to proceed, please click the Login/logout menu and login first.";
            this.ShowMessageBox(Message, "Visitor warning.", MessageBoxOption.Ok);
        }
        //bool IsPasswordOk() {
        //    string ThePassword = "123";
        //    bool rtn = false;
        //    string password = this.ShowInputBox("Please enter password.", "Password", "");
        //    if ((password != null) && password.Length > 0) {
        //        if (password != ThePassword) {
        //            string Message = "The password that you have just entered is invalid, please enter again.";
        //            this.ShowMessageBox(Message, "Invalid password!", MessageBoxOption.Ok);      
        //            }                
        //        else {
        //           rtn = true;
        //        }
        //    }
        //    return rtn;
        //}
        
        partial void Home_InitializeDataWorkspace(List<IDataService> saveChangesTo) {
            if (this.Application.CurrentUser == null) {
                this.Application.CurrentUser = this.DataWorkspace.FtgQcData.Users_Single("Visitor");
            }            
        }

        partial void Home_Activated() {
            this.CurrentUserName = this.Application.CurrentUser.Name; 
        }
      
    }
}
